package com.beidu.lottery.call.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.StringUtils;

@Getter
@AllArgsConstructor
public enum OrderStatusEnum {

    UNISSUED(0, 0, "未发放"),
    TO_BE_DISTRIBUTED(1, 1, "待发放"),
    ISSUED(2, 2, "已发放"),
    EXPIRED(3, 3, "已失效"),

    ;

    private final Integer id;

    private final Integer code;

    private final String msg;

    public static OrderStatusEnum findByCode(Integer code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        for (OrderStatusEnum statusEnum : OrderStatusEnum.values()) {
            if (statusEnum.code.equals(code)) {
                return statusEnum;
            }
        }
        return null;
    }

    public static OrderStatusEnum findByMsg(String msg) {
        if (StringUtils.isEmpty(msg)) {
            return null;
        }
        for (OrderStatusEnum statusEnum : OrderStatusEnum.values()) {
            if (statusEnum.msg.equals(msg)) {
                return statusEnum;
            }
        }
        return null;
    }

    public static OrderStatusEnum findById(String id) {
        if (StringUtils.isEmpty(id)) {
            return null;
        }
        for (OrderStatusEnum statusEnum : OrderStatusEnum.values()) {
            if (statusEnum.id.equals(id)) {
                return statusEnum;
            }
        }
        return null;
    }

}
